package cn.zzszxyy.hr.service;

import cn.zzszxyy.hr.model.EmployeeEntity;
import cn.zzszxyy.hr.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 作者:张伟
 * <p>
 * 联系:adamzzww@163.com
 * 时间:2016-11-28
 * 说明:无
 */
@Service
public class EmployeeService {

    @Autowired
    private EmployeeRepository employeeRepository;

    public Page<EmployeeEntity> findAllWithPage(int pageIndex, int pageSize) {
        PageRequest pageRequest = new PageRequest(--pageIndex, pageSize);
        Page<EmployeeEntity> employeeList = employeeRepository.findAll(pageRequest);
        return employeeList;
    }

    public Page<EmployeeEntity> findByEmployeeNameLike(String employeeName, int pageIndex, int pageSize) {
        PageRequest pageRequest = new PageRequest(--pageIndex, pageSize);
        return employeeRepository.findByEmployeeNameLike(employeeName, pageRequest);
    }

    public EmployeeEntity findOne(int id) {
        return employeeRepository.findOne(id);
    }

    public EmployeeEntity save(EmployeeEntity employeeEntity) {
        return employeeRepository.save(employeeEntity);
    }

    @Transactional
    public void delete(int id) {
        //删除：本表记录
        employeeRepository.delete(id);
    }


}
